package com.atguigu1;

import org.junit.Test;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * @auther user
 * @date 2021/12/5 - 20:44
 */
public class PropertiesTest {
    @Test
    public void testProperties() throws Exception {
        //类加载器， 这里使用系统类加载器
        //InputStream inputStream = PropertiesTest.class.getClassLoader().getResourceAsStream("jdbc.properties");
        InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("jdbc.properties");
        Properties properties = new Properties();
        properties.load(inputStream);
        //基本四要素
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driverClass = properties.getProperty("driverClass");
        //加载驱动
        Class.forName(driverClass);
        //获取连接
        Connection connection = DriverManager.getConnection(url, user, password);
        System.out.println("connection = " + connection);


    }
}
